{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c95eb1c2-1a8a-4ad6-95bc-23b9abe507ba",
   "metadata": {},
   "source": [
    "> A unified interface for LLMs。大模型的中间商，也可能是中间商的中间商；\n",
    "\n",
    "- 不是所有的模型都可以方便地本地部署 (*2 gpu memory)\n",
    "    - qwen/qwen-2.5-72b-instruct\n",
    "    - deepseek-v3；\n",
    "    - llama3.1-405b；\n",
    "- 远端api快速验证，evaluate，科研或者工程；\n",
    "- 虚拟信用卡\n",
    "    - https://bewildcard.com/i/CHUNHUI3\n",
    "- 关于一个模型的不同 provider 的路由策略（provider routing）\n",
    "    - https://openrouter.ai/docs/provider-routing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8839a1bb-019b-42be-bbf3-5ed0ee5942d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "449661f7-3031-4ccd-bb00-9d625f7ff440",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv, find_dotenv\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "24dba6a5-9fc6-4e00-8fad-0b5c5c284c41",
   "metadata": {},
   "outputs": [],
   "source": [
    "assert load_dotenv(find_dotenv())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3cc1ad49-dfd8-44a8-8a8b-accad01b7b8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I am an instance of OpenAI's language model, specifically based on the GPT-4 architecture. My design allows me to understand and generate human-like text based on the input I receive. I can assist with a wide range of tasks, from answering questions and providing explanations to generating creative content and offering advice. Let me know how I can help you today!\n"
     ]
    }
   ],
   "source": [
    "client = OpenAI(\n",
    "  base_url=\"https://openrouter.ai/api/v1\",\n",
    "  api_key=os.getenv('OPENROUTER_API_KEY'),\n",
    ")\n",
    "\n",
    "completion = client.chat.completions.create(\n",
    "  model=\"deepseek/deepseek-chat\",\n",
    "  messages=[\n",
    "    {\n",
    "      \"role\": \"user\",\n",
    "      \"content\": \"what model are you?\"\n",
    "    }\n",
    "  ]\n",
    ")\n",
    "print(completion.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08e42d1d-2faf-41ee-b867-f4786bfb6c5b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
